from time import *

from edge_util import *
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from ddddocr学习 import get_distance

util = EdgeUtil()
# 使用selenium打开一个网页
url = 'https://ehall.wynu.edu.cn/new/index.html'
wynu_ehall = util.start_page(url)
DELAY = 1
sleep(DELAY)
button = wynu_ehall.find_element(By.CLASS_NAME, 'amp-no-login-en')
button.click()

sleep(DELAY)
username_input = wynu_ehall.find_element(By.ID, 'username')
password_input = wynu_ehall.find_element(By.ID, 'password')

sleep(DELAY)
username_input.send_keys('3234241')
password_input.send_keys('fasdfe')
sleep(DELAY)

login_submit = wynu_ehall.find_element(By.ID, 'login_submit')
login_submit.click()
sleep(DELAY)


# 寻找背景图片并且保存到本地
backgrount = wynu_ehall.find_element(By.TAG_NAME, 'canvas')
background_path = './imgs/background.png'
backgrount.screenshot(background_path)
distance = get_distance(back_path=background_path, target_path='./imgs/wynu_target.png')
print(distance)


# 查找滑块，然后点击并且移动指定距离
slider = wynu_ehall.find_element(By.CLASS_NAME, 'slider')
actions = ActionChains(wynu_ehall)
actions.click_and_hold(slider).move_by_offset(distance, 0).release().perform()

input()